<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Builds and solves a simple linear program</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/html/simple_LP.html">
<link rel="stylesheet" href="../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Builds and solves a simple linear program</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
echo <span class="string">on</span>

n = 100;
A = randn(0.5*n,n);
b = randn(0.5*n,1);
c = randn(n,1);
d = randn;
cvx_begin
   variable <span class="string">x(n)</span>
   dual <span class="string">variables</span> <span class="string">y</span> <span class="string">z</span>
   minimize( c' * x + d )
   subject <span class="string">to</span>
      y : A * x == b;
      z : x &gt;= 0;
cvx_end

echo <span class="string">off</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
n = 100;
A = randn(0.5*n,n);
b = randn(0.5*n,1);
c = randn(n,1);
d = randn;
cvx_begin
   variable x(n)
   dual variables y z
   minimize( c' * x + d )
   subject to
      y : A * x == b;
      z : x &gt;= 0;
cvx_end
 
Calling sedumi: 100 variables, 50 equality constraints
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 50, order n = 101, dim = 101, blocks = 1
nnz(A) = 5000 + 0, nnz(ADA) = 2500, nnz(L) = 1275
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.12E+00 0.000
  1 :  -8.09E-01 7.83E-01 0.000 0.3694 0.9000 0.9000  -0.53  1  1  3.5E+01
  2 :  -2.53E+00 2.90E-01 0.000 0.3700 0.9000 0.9000   0.14  1  1  2.0E+01
  3 :  -2.82E+00 8.96E-02 0.000 0.3094 0.9000 0.9000  -0.21  1  1  1.5E+01
  4 :  -3.12E+00 5.69E-03 0.000 0.0634 0.9900 0.9900  -0.74  1  1  1.7E+01
  5 :  -2.98E+00 1.84E-06 0.000 0.0003 0.9999 0.9999  -0.98  1  1  
Dual infeasible, primal improving direction found.
iter seconds  |Ax|    [Ay]_+     |x|       |y|
  5      0.0   3.0e-14   1.6e-18   1.7e+01   1.0e-18

Detailed timing (sec)
   Pre          IPM          Post
1.000E-02    2.000E-02    0.000E+00    
Max-norms: ||b||=2.651167e+00, ||c|| = 2.521543e+00,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.
------------------------------------------------------------
Status: Unbounded
Optimal value (cvx_optval): -Inf

echo off
</pre>
</div>
</body>
</html>